package com.lz.football.module.club
{
	import com.common.utils.DisplayObjectUtil;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.ClubEvent;
	import com.liangzhong.model.AppData;
	
	import common.BaseView.BaseView;
	import common.comp.TabButtonBar;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.Alert;
	import lz.controls.LButton;
	
	/**
	 *更换国家 
	 * @author Administrator
	 * 
	 */	
	public class ChangeNationView extends BaseView
	{
		/**
		 *确定按钮 
		 */
		private var _Yes:SimpleButton;
		/**
		 *取消按钮 
		 */
		private var _No:SimpleButton;
		/**
		 *选中的国家 
		 */
		private var _selectNation:MovieClip;
		/**
		 *选中的国家ID 
		 */
		private var _selectNationId:int;
		
		/**
		 *选项卡 
		 */		
		private var buttonBar :TabButtonBar;
		
		
		public function ChangeNationView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.changeNationView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.changeNationBg;
			isDrag = true;
			isCloseBtn = true;
			_viewHeight = symbolSkin.height;
			_viewWidth  =symbolSkin.width;
			moveClose(symbolSkin.width - 32,32);
			_Yes = symbolSkin.mc._Yes;
			_No = symbolSkin.mc._No;
			
			//			var i :int = 0;
			var lbtn :LButton;
			var lbtns :Array = [];
			buttonBar = new TabButtonBar();
			for(var i:int = 1;i<= 6;i++)
			{
				symbolSkin.mc.settingMC2["country_" + i].nationIcon.gotoAndStop(i);
				symbolSkin.mc.settingMC2["country_" + i].nationIcon.mouseChildren = false;
				symbolSkin.mc.settingMC2["country_" + i].nationIcon.mouseEnabled = false;
				//				symbolSkin.mc.settingMC2["country_" + i].btn.addEventListener(MouseEvent.CLICK,onClickHandler);
				
				lbtn = new LButton(symbolSkin.mc.settingMC2["country_" + i].btn);
				lbtn.enable = true;
				lbtns.push(lbtn);
			}
			//			selectCountry(symbolSkin.mc.settingMC2["country_" + 1]);
			
			buttonBar.setButtons(lbtns);
			buttonBar.selectTabButton(lbtns[0]);
			
			onTabChangeHandler();
			addEvtListener();
			onResizeHandler();
		}
		override public function addEvtListener():void
		{
			super.addEvtListener();
			_Yes.addEventListener(MouseEvent.CLICK,onSureHandler);
			_No.addEventListener(MouseEvent.CLICK,onCloseHandler);
			buttonBar.addEventListener(Event.CHANGE,onTabChangeHandler);
		}
		/**
		 *选项卡改变 
		 * @param e
		 * 
		 */		
		private function onTabChangeHandler(e :Event = null):void
		{
			_selectNationId = buttonBar.selectType + 1;
			symbolSkin.mc.settingMC2["country_" + _selectNationId].nationIcon.gotoAndStop(_selectNationId);
			symbolSkin.mc.settingMC2.descMc.gotoAndStop(_selectNationId);
			symbolSkin.mc.settingMC2.actionMC.mc.descMc.gotoAndStop(_selectNationId);
			symbolSkin.mc.settingMC2.actionMC.mc.mc.mc.gotoAndStop(_selectNationId);
			symbolSkin.mc.settingMC2.actionMC.mc.gotoAndPlay(1);
		}
		
		protected function onSureHandler(event:MouseEvent):void
		{
			
			if(_selectNationId == AppData.getInstance().clubDatamanager.clubInfo.country)
			{
				Alert.showErrorTip("选择更换的国家与现在国家一致！");
				return;
			}
			if(AppData.getInstance().clubDatamanager.clubInfo.countrymodify == 0)
			{
				Alert.show("本次免费更换国家，是否要更换？","",Alert.NO,GlobalDef.AlertContainer,sureChange);
			}else
			{
				if(AppData.getInstance().clubDatamanager.clubInfo.cashpoint < 688)
				{
					Alert.noCashAlert("更换国家需要花费688点券\n现有点券不足，是否前往充值？");
				}else
				{
					Alert.show("更换国家需花费688点券，且更换国籍之后，国家挑战赛中的数据将被清空，确定要更换吗？","",Alert.NO,GlobalDef.AlertContainer,sureChange);	
				}
				
				
				
			}
				
			
			//			
		}
		private function sureChange($type:int):void
		{
			if(Alert.YES == $type)
				AppEventDispatcher.getInstance().dispatchEvent(new ClubEvent(ClubEvent.CHANGE_NATION,{nationId:_selectNationId}));
		}
		
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			_Yes.removeEventListener(MouseEvent.CLICK,onSureHandler);
			_No.removeEventListener(MouseEvent.CLICK,onCloseHandler);
		}
		override public function destroyView():void
		{
			//			isDrag = false;
			
			removeEvtListener();
			buttonBar.destroyView();
			buttonBar = null;
			_selectNation = null;
			super.destroyView();
			_Yes = null;
			_No = null;
		}
	}
}